<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Hity
 *
 * @author Kopi
 */
class DalProducers extends DatabaseAbstract{
    
    protected $_name = 'producers';
    protected $_primary = 'id_Producers';
    protected $_class = 'Producers';
    protected $_collection = 'CollectionProducers';
        
    /**
     * 
     * @param type $programId
     * @param type $limit
     * @return type 
     */
    public function listGamesToProgram($programId){        
        $where = $this->getAdapter()->quoteInto('id_series = ?', $programId);
        $sql = $this->getAdapter()->select()
                    ->from(array('g'=>$this->_name))
                    ->where($where)
                    ->where('is_default = 1')
                    ->order("type ASC")
                    ->order("group ASC")
            ;    
        $params = func_get_args();
        return $this->listFromSqlToCollection($sql,$params);
    }
    
    
    public function updateGroupIds(){
        $gamesCollection = $this->getAll('title ASC');	
        
        $groupId = 1;
        $lastTitle = '';
        while ($game = $gamesCollection->iterator()){
            if ($game->getType() == 3){
                $game->setGroup($groupId);
                if ($game->getTitle() != $lastTitle){
                    $groupId++;
                    $lastTitle = $game->getTitle();
                }
                $this->save($game);
            }
        }
    }
    
    public function search($phrase, $order){
        $whereOne = $this->getAdapter()->quoteInto('title LIKE ?', '%'.$phrase.'%');
        $sql = $this->select()
                    ->order($order)
                    ->where($whereOne);
        
        
        $params = func_get_args();
        return $this->listFromSqlToCollection($sql, $params);
    }
    
    
    public function get_name() {
	return $this->_name;
    }

 
    public function get_primary() {
	return $this->_primary;
    }


    public function get_class() {
	return $this->_class;
    }

}

?>
